package com.zhy.learning.demo.controller;

import com.zhy.learning.demo.mapper.UserMapper;
import com.zhy.learning.demo.pojo.User;
import com.zhy.learning.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhy
 * @version 1.0.0
 * @ClassName UserController.java
 * @Description TODO
 * @createTime 2021年09月01日 20:18:00
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/find/{name}")
    public User findByName(@PathVariable("name") String name) {
        return userService.findByName(name);
    }

    @RequestMapping("/update")
    public User update(@RequestBody User user) {
        userMapper.updateByUser(user);
        return userService.selectById(user.getId());
    }


}
